<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>首页</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="/static/js/bootstrap/css/bootstrap.css">

  </head>
  <body>
    <div class="container">
        <table class="table border table-striped table-hover" width="80%" align="center">
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Age</th>
            </tr>
             <tr>
                <th>101</th>
                <th>雷军</th>
                <th>20</th>
            </tr>
              <tr>
                <th>101</th>
                <th>雷军</th>
                <th>20</th>
            </tr>
              <tr>
                <th>101</th>
                <th>雷军</th>
                <th>20</th>
            </tr>
        </table>

        <ul class="list-group news">


        </ul>
        <button class="button btn-success" id="getmore">查看更多</button>
    </div>





    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="/static/admin/js/vendor/jquery/jquery.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="/static/js/bootstrap/js/bootstrap.js"></script>

    <script>

        let current = 0;

        function loadData(offset=0, size=1){
            $.ajax({
                url: "/json/",
                method: "get",
                data: {
                    "offset": offset,
                    "size": size
                },
                success: (res)=>{
                    console.log(res)
                    if(res.code == 0){
                        res.datas.forEach(function(item){
                         $(".news").append(`
                            <li class="list-group-item">${item.title}</li>
                        `)
                        })

                    }
                    current += size;
                }
            });
        }

        loadData(current);

        $("#getmore").click(function(){
            loadData(current);
        })



    </script>


  </body>
</html>